package logic;

import java.util.ArrayList;
import java.util.List;

public class CardDataBase {
	private List<MetroCard> cards;
	private List<MetroCard> couldPass;
	private List<MetroCard> accessDenied;
	private double passPrice;
	private double coeficientStudent;
	private double coeficientSchool;
	
	public CardDataBase(){
		cards = new ArrayList<>();
		couldPass = new ArrayList<>();
		accessDenied = new ArrayList<MetroCard>();
	}
	
        public CardDataBase( double passPrice, double coefStud, double coefSchool){
            this();
            this.passPrice = passPrice;
            coeficientStudent = coefStud;
            coeficientSchool = coefSchool;
	}
        
	public boolean  findCard( MetroCard card ){
		return cards.contains(card);
	}
	 
	public double getCoeficientStudent() {
		return coeficientStudent;
	}

	public void setCoeficientStudent(double coeficientStudent) {
		this.coeficientStudent = coeficientStudent;
	}

	public double getPassPrice() {
		return passPrice;
	}

	public void setPassPrice(double passPrice) {
		this.passPrice = passPrice;
	}

	public double getCoeficientPupil() {
		return coeficientSchool;
	}

	public void setCoeficientPupil(double coefSchool) {
		this.coeficientSchool = coefSchool;
	}
	
	public void addLog( MetroCard metroCard, boolean wasPassed){
		if ( wasPassed ){
			couldPass.add(metroCard);
		}
		else{
			accessDenied.add(metroCard);
		}
	}
	
	public boolean addCard( MetroCard metroCard){
            cards.add( metroCard );
            return true;
	}
       
        public String printLog(){
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("ALL:\n");
            stringBuilder.append("passed:\n");
            for ( MetroCard item:couldPass){
                stringBuilder.append( item.getType() );
                stringBuilder.append(" ");
                stringBuilder.append(item.getCardId());
                stringBuilder.append("\n");
            }
            stringBuilder.append("access denied for:\n");
            for ( MetroCard item:accessDenied){
                stringBuilder.append( item.getType() );
                stringBuilder.append(" ");
                stringBuilder.append(item.getCardId());
                stringBuilder.append("\n");
            }
            return stringBuilder.toString();
        }
        
        public String printLog( CardType cardType){
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append( cardType );
            stringBuilder.append("S passed:\n");
            for ( MetroCard item:couldPass){
                if ( item.getType() == cardType ){
                    stringBuilder.append( item.getType() );
                    stringBuilder.append(" ");
                    stringBuilder.append(item.getCardId());
                    stringBuilder.append("\n");
                }
            }
            stringBuilder.append("access denied for:\n");
            for ( MetroCard item:accessDenied){
                if ( item.getType() == cardType ){
                    stringBuilder.append( item.getType() );
                    stringBuilder.append(" ");
                    stringBuilder.append(item.getCardId());
                    stringBuilder.append("\n");
                }
            }
            return stringBuilder.toString();
        }
}
